package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.system.domain.SysLabels;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.system.service.ISysLabelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签Controller
 *
 * @author king
 * @date 2022-07-15
 */
@RestController
@RequestMapping("/system/labels")
public class SysLabelsController extends BaseController {
    @Autowired
    private ISysLabelsService sysLabelsService;

    /**
     * 查询标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:labels:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLabels sysLabels) {
        startPage();
        List<SysLabels> list = sysLabelsService.selectSysLabelsList(sysLabels);
        return getDataTable(list);
    }

    /**
     * 获取所有的标签
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:labels:all')")
    @GetMapping("/all")
    public AjaxResult getAllLabels() {
        List<SysLabels> sysLabelsList = sysLabelsService.selectSysLabelsList(null);
        return AjaxResult.success(sysLabelsList);
    }

    /**
     * 导出标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:labels:export')")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLabels sysLabels) {
        List<SysLabels> list = sysLabelsService.selectSysLabelsList(sysLabels);
        ExcelUtil<SysLabels> util = new ExcelUtil<SysLabels>(SysLabels.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:labels:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysLabelsService.selectSysLabelsById(id));
    }

    /**
     * 新增标签
     */
    @PreAuthorize("@ss.hasPermi('system:labels:add')")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLabels sysLabels) {
        return toAjax(sysLabelsService.insertSysLabels(sysLabels));
    }

    /**
     * 修改标签
     */
    @PreAuthorize("@ss.hasPermi('system:labels:edit')")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLabels sysLabels) {
        return toAjax(sysLabelsService.updateSysLabels(sysLabels));
    }

    /**
     * 删除标签
     */
    @PreAuthorize("@ss.hasPermi('system:labels:remove')")
    @Log(title = "标签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysLabelsService.deleteSysLabelsByIds(ids));
    }
}
